﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.ProductTechnologyView>
@{
    //ViewBag.Title = "Index";
    var creatorName = ViewBag.creatorName;
    var productName = ViewBag.productName;
    var beginTime = ViewBag.beginTime;
    var endTime = ViewBag.endTime;
}
<section class="content-header">
    <h1>
        订单分配
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("PurchaseQuery", "Purchase")">订单分配查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    <div class="col-sm-12 col-md-9">
                        @*<a class="btn btn-primary" href="@Url.Action("AddPurchase", "Purchase")" title="新建"><i class="fa fa-plus-square"></i>&nbsp;新建采购单</a>*@
                        <button type="button" class="btn btn-primary" onclick="query();" title="查询"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
                        <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <div class="input-group">
                        </div>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table class="footable table table-stripped table-bordered table-hover" id="footable" data-filter=#filter>
                        <thead>
                            <tr>
                                <th data-sort-ignore="true">
                                    产品名称
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    申请人
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    申请时间
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    希望交货期
                                </th>
                                @*<th data-hide="phone,tablet" data-sort-ignore="true">
                                        供应商
                                    </th>*@
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    数量
                                </th>
                                @*<th data-hide="phone,tablet" data-sort-ignore="true">
                                        金额
                                    </th>*@
                                @*<th data-hide="phone,tablet" data-sort-ignore="true">
                                        订单号
                                    </th>*@
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    类型
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    状态
                                </th>
                                <th data-sort-ignore="true">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (null != Model)
                            {
                                foreach (var item in Model)
                                {
                                    <tr>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => item.ProductName)*@
                                            <a class="productinfo" href="javascript:void(0)" data-mid="@item.ProductId">@item.ProductName</a>
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.UserName)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.ApplyTime)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.SendTime)
                                        </td>
                                        @*<td>
                                                @Html.DisplayFor(modelItem => item.CustomerName)
                                            </td>*@
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Amount)
                                        </td>
                                        @*<td>
                                                @Html.DisplayFor(modelItem => item.Price)
                                            </td>*@
                                        @*<td>
                                                @Html.DisplayFor(modelItem => item.Number)
                                            </td>*@
                                        <td>
                                            @if (item.PurchaseType == 1)
                                            {
                                                @Html.Raw("订单产品")
                                            }
                                            @if (item.PurchaseType == 2)
                                            {
                                                @Html.Raw("自定义采购")
                                            }
                                        </td>
                                        <td>
                                            @if (item.PurchaseStatus == -1)
                                            {
                                                @Html.Raw("生产")
                                            }
                                            else if (item.PurchaseStatus == 1)
                                            {
                                                @Html.Raw("等待分配")
                                            }
                                            else if (item.PurchaseStatus == 6)
                                            {
                                                @Html.Raw("采购")
                                            }
                                            @*else if (item.PurchaseStatus == 5)
                                                {
                                                    @Html.Raw("采购完成")
                                                }
                                                else if (item.PurchaseStatus == 8)
                                                {
                                                    @Html.Raw("单独采购")
                                                }*@
                                            else
                                            {
                                                @Html.Raw("采购")
                                            }
                                        </td>
                                        <td>
                                            @*<span class="btn bg-blue btn-xs" style="margin-left: 8px;" onclick="ShowProductModal('@item.ProductId')">产品信息</span>*@
                                            @*<span class="btn bg-blue btn-xs" style="margin-left: 8px;" onclick="ShowModal('@item.OrderId')">订单信息</span>*@
                                            @*<span class="btn bg-blue btn-xs" style="margin-left: 8px;" onclick="Technologyinfo('@item.OrderProductId')">工艺详情</span>*@
                                            @if (item.PurchaseStatus == 1)
                                            {
                                                <span>
                                                    <a class="btn bg-blue btn-xs" href="javascript:void(0)" onclick="ToPurchase('@item.OrderProductId', '@item.PurchaseId', '@item.Amount')">采购</a>&nbsp;
                                                    <span class="btn bg-blue btn-xs" onclick="ToWork('@item.OrderProductId', '@item.PurchaseId', '@item.Amount')">生产</span>
                                                </span>
                                            }
                                            else
                                            {
                                                @*<a class="btn bg-blue btn-xs" href="@Url.Action("PurchaseLookInfo", "Purchase", new {tId = item.PurchaseId, status = 10})">采购查看</a>*@
                                            }

                                            @*@if (item.PurchaseStatus == 2 || item.PurchaseStatus == 4 || item.PurchaseStatus == 5)
                                                {
                                                    <a class="btn bg-blue btn-xs" href="@Url.Action("PurchaseLookInfo", "Purchase", new {tId = item.PurchaseId, status = 10})">查看</a>
                                                }
                                                @if (item.PurchaseStatus == 3)
                                                {
                                                    <a class="btn bg-blue btn-xs" href="@Url.Action("PurchaseLookInfo", "Purchase", new {tId = item.PurchaseId, status = 10})">查看</a>
                                                    <a class="btn bg-blue btn-xs" href="@Url.Action("PurchaseLookInfo", "Purchase", new {tId = item.PurchaseId, status = item.PurchaseStatus})">确认</a>
                                                }*@
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                        @if (null != Model)
                        {
                            <tfoot>
                                <tr>
                                    <td colspan="8">
                                        每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                        @Html.PagedListPager(Model, page => Url.Action("PurchaseQuery", new { page, creatorName, productName, beginTime, endTime }))
                                    </td>
                                </tr>
                            </tfoot>
                        }
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<!--查询对话框-->
<div class="modal" id="queryDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查询</h4>
            </div>
            <form class="form-horizontal" id="frmquery" action="@Url.Action("PurchaseQuery", "Purchase")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 申请人 </label>
                        <div class="col-sm-8">
                            @*<input type="hidden" class="form-control formId" id="Id" name="Id" />*@
                            <input type="text" class="form-control" id="creatorName" name="creatorName" value="@creatorName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 产品名称 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="productName" name="productName" value="@productName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 开始时间 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control Timedatepicker" id="beginTime" name="beginTime" value="@beginTime" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 结束时间 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control Timedatepicker" id="endTime" name="endTime" value="@endTime" />
                        </div>
                    </div>
                    @*<div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for=""> 上级模块</label>
                            <div class="col-sm-8">
                                <input type="hidden" name="ParentName" id="ParentName" />
                                <select class="form-control" type="select" id="ParentId" name="ParentId">
                                    <option value="">==请选择==</option>
                                    <option value="1">1</option>
                                </select>
                            </div>
                        </div>*@
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();

            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month"//选择日期后，不会再跳转去选择时分秒
            });
            //$(".form_datetime").datetimepicker('setStartDate', date);//设置 初始时间(放在这个位置及顺序  固定)
            //$(".switch").click(function () {
            //alert("ok");
            //$(".datetimepicker-months table tr td span").attr("disabled", false);
            //$(".datetimepicker-months table tr td span").removeClass("disabled");
            //});
        });

        function query() {
            $('#queryDlg').modal();
        }

        function ToWork(opid, purid, amount) {
            layer.prompt({ title: '请输入数量【下一步：查询加工申请】', formType: 3 }, function (pass, index) {
                if (isNaN(pass)) {
                    alert("数量输入有误");
                    return false;
                }
                pass = pass / 1;
                if (amount / 1 < pass) {
                    alert("数量输入过大");
                    return false;
                }
                layer.close(index);
                $.ajax({
                    url: "/Purchase/ToWork",
                    type: "Post",
                    data: { opid: opid, purid: purid, amount: pass },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $.modalAlert("操作成功", "success");
                        location.reload();
                    }
                });
            });

            /*top.layer.confirm('确定生产吗？', {
                icon: "fa-exclamation-circle",
                title: "系统提示",
                btn: ['确认', '取消'],
                btnclass: ['btn btn-primary', 'btn btn-danger'],
            }, function () {
                $.ajax({
                    url: "/Purchase/ToWork",
                    type: "Post",
                    data: { opid: opid, purid: purid },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $.modalAlert("操作成功", "success");
                        location.reload();
                    }
                });
            }, function () {

            });*/
        }

        function ToPurchase(opid, purid, amount) {
            layer.prompt({ title: '请输入数量 【下一步：采购合并】', formType: 3 }, function (pass, index) {
                if (isNaN(pass)) {
                    alert("数量输入有误");
                    return false;
                }
                pass = pass / 1;
                if (amount / 1 < pass) {
                    alert("数量输入过大");
                    return false;
                }
                layer.close(index);

                $.ajax({
                    url: "/Purchase/InToPurchaseCompose",
                    type: "Post",
                    data: { opid: opid, purid: purid, amount: pass },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data == "0") {
                            $.modalAlert("操作成功", "success");
                        } else {
                            $.modalAlert("操作失败", "error");
                        }
                        location.reload();
                    }
                });
            });

            /*top.layer.confirm('确定采购吗？', {
                icon: "fa-exclamation-circle",
                title: "系统提示",
                btn: ['确认', '取消'],
                btnclass: ['btn btn-primary', 'btn btn-danger'],
            }, function () {
                $.ajax({
                    url: "/Purchase/InToPurchaseCompose",
                    type: "Post",
                    data: { opid: opid, purid: purid },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data == "0") {
                            $.modalAlert("操作成功", "success");
                        } else {
                            $.modalAlert("操作失败", "error");
                        }
                        location.reload();
                    }
                });
            }, function () {

            });*/
        }

        //产品信息弹窗
        function ShowProductModal(id) {
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
        //订单信息弹窗
        function ShowModal(id) {
            var options = {
                id: null,
                title: '订单信息',
                width: "100%",
                height: "100%",
                url: "../Order/OrderInfo?OID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

        function Technologyinfo(id) {
            var options = {
                id: null,
                title: '工艺信息',
                width: "100%",
                height: "100%",
                url: "../Technology/TechnologyInfo?tId=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
        $(".productinfo").click(function () {
            var mid = $(this).data('mid');
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "../Product/Info?PID=" + mid,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        });

    </script>
}





